package com.avcdata.aoscustommade.activity;

import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.avcdata.aoscustommade.R;
import com.avcdata.aoscustommade.bean.BaseResponseBean;
import com.avcdata.aoscustommade.bean.GetVerificationCodeBean;
import com.avcdata.aoscustommade.bean.LocatityCacheData;
import com.avcdata.aoscustommade.bean.LoginActivityBean;
import com.avcdata.aoscustommade.bean.UserRegionBean;
import com.avcdata.aoscustommade.bean.UserRegionBeanChild;
import com.avcdata.aoscustommade.bean.VerifyNoteBean;
import com.avcdata.aoscustommade.bean.VerifyPhotoNumberBean;
import com.avcdata.aoscustommade.main.BaseActivity;
import com.avcdata.aoscustommade.model.LoginActivityModel;
import com.avcdata.aoscustommade.presenter.LoninActivityPresenter;
import com.avcdata.aoscustommade.receiver.MyReceiver;
import com.avcdata.aoscustommade.utils.AppActivityManager;
import com.avcdata.aoscustommade.utils.AvcLogUtils;
import com.avcdata.aoscustommade.utils.AvcConstants;
import com.avcdata.aoscustommade.utils.SharedPreferencesUtils;
import com.avcdata.aoscustommade.utils.TextUitl;
import com.avcdata.aoscustommade.utils.ToastUtils;
import com.avcdata.aoscustommade.utils.http.AvcHttpUtils;
import com.avcdata.aoscustommade.utils.http.AvcJsonHttpResponseHandler;
import com.avcdata.aoscustommade.view.LoginActivityView;
import com.avcdata.aoscustommade.view.TimeCount;
import com.avcdata.national.activity.ModuleSelectActivity;
import com.avcdata.national.activity.PersonalAttentionCategoryActivity;
import com.avcdata.national.module.UserCompetingBrandInfo;
import com.avcdata.national.network.JsonRunnable;
import com.avcdata.national.network.SimulationJSON;
import com.avcdata.national.network.ThreadPoolUtils;
import com.google.gson.Gson;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


/**
 * Created by c.c on 2017/2/26.
 * 登录页面
 */
public class Login_Activity extends BaseActivity implements LoginActivityView {

    @ViewInject(R.id.userAccount)
    private EditText userAccount;
    @ViewInject(R.id.userPassword)
    private EditText userPassword;
    //    @ViewInject(R.id.passwordEyeImg)
//    private ImageView passwordEyeImg;
    @ViewInject(R.id.forgetPassword)
    private TextView forgetPassword;
    @ViewInject(R.id.rememberimg)
    private ImageView rememberimg;
    @ViewInject(R.id.rememberPassword_lay)
    private LinearLayout rememberPassword_lay;
    @ViewInject(R.id.loginBtn)
    private Button loginBtn;

    //获取验证码
    @ViewInject(R.id.user_line)
    private ImageView user_line;
    @ViewInject(R.id.usercode_lay)
    private RelativeLayout usercode_lay;
    @ViewInject(R.id.usertextcode)
    private EditText usertextcode;
    @ViewInject(R.id.login_tips)
    private TextView login_tips;
    @ViewInject(R.id.usercodebtn)
    private Button usercodebtn;

    private SharedPreferencesUtils sp;
    private TimeCount timeCount;
    private boolean isNativeLogined = true;

    //异常情况
    @ViewInject(R.id.loadfail)
    private View loadfail;
    @ViewInject(R.id.jiazai_layout)
    private LinearLayout jiazai_layout;
//    @ViewInject(R.id.load_fail_layout)
//    private LinearLayout load_fail_layout;

    private String account = "";
    private MyReceiver myReceiver;
    private LoninActivityPresenter loninActivityPresenter;


    //ceshiyong
    @Override
    public void initView() {
        setContentView(R.layout.activity_login);
        AppActivityManager.getAppManager().addActivity(this);
        ViewUtils.inject(this);
    }

    @Override
    public void initInstall() {
        sp = new SharedPreferencesUtils(this);
        IntentFilter filter=new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
        myReceiver=new MyReceiver(loadfail);
        this.registerReceiver(myReceiver, filter);
        isRememberPassword(false);
//        isShowPassword(false);
        timeCount = new TimeCount(this,usertextcode, usercodebtn, 60000, 1000);

        loninActivityPresenter = new LoninActivityPresenter(this, new LoginActivityModel(Login_Activity.this));

    }

    @Override
    public void initData() {
        account = sp.getUserAccount();
        String userPasswordString = sp.getUserPassword();
        if (TextUitl.isEmpty(account)) {
//            user_line.setVisibility(View.VISIBLE);
//            usercode_lay.setVisibility(View.VISIBLE);
        } else {
            userAccount.setText(account);
        }
        user_line.setVisibility(View.GONE);
        usercode_lay.setVisibility(View.GONE);

        if (!TextUitl.isEmpty(userPasswordString)) {
            if (sp.getRememberPassword()) {
                userPassword.setText(userPasswordString);
            }

        }

    }

    @Override
    public void evenControl() {
//        passwordEyeImg.setOnClickListener(this);
        forgetPassword.setOnClickListener(this);
        rememberimg.setOnClickListener(this);
        rememberPassword_lay.setOnClickListener(this);
        loginBtn.setOnClickListener(this);
        usercodebtn.setOnClickListener(this);
    }

    private boolean isTouch = true;
    @Override
    public void onClickEvent(View view) {
        switch (view.getId()) {
//            case passwordEyeImg:
//                isShowPassword(true);
//                break;
            case R.id.forgetPassword:
                Intent intent = new Intent(this, ForgetPassword_Activity.class);
                startActivityForResult(intent,1);
                break;
            case R.id.rememberimg:
            case R.id.rememberPassword_lay:
                isRememberPassword(true);
                break;
            case R.id.usercodebtn:
                if (checkAccount()) {
                    if (usercodebtn.getText().toString().trim().equals("重新获取")){
                        usertextcode.setText("");
                    }
                    loadCode();
                }
                break;
            case R.id.loginBtn:
                if (checkAccount()&&checkNewWeek()) {
                    if (isTouch){
                        isTouch = false;
                        loadCheackAccount();
                    }
                }
                break;
        }
    }



    /**
     * 是否获取最新周
     * @return
     */
    private boolean checkNewWeek() {
        if (TextUitl.isEmpty(sp.getNewWeek())) {
            ToastUtils.showShort(Login_Activity.this, "网络异常请重新进入应用");
            return false;
        }
        return true;
    }



    private void loading(boolean isFail, boolean isLoading) {
        if (isFail) {
            if (isLoading) {
                loadfail.setVisibility(View.GONE);
//                load_fail_layout.setVisibility(View.GONE);
                jiazai_layout.setVisibility(View.GONE);
            } else {
                loadfail.setVisibility(View.VISIBLE);
//                load_fail_layout.setVisibility(View.VISIBLE);
                jiazai_layout.setVisibility(View.GONE);
            }
        } else {
            if (isLoading) {
                loadfail.setVisibility(View.VISIBLE);
//                load_fail_layout.setVisibility(View.GONE);
                jiazai_layout.setVisibility(View.VISIBLE);
            } else {
                loadfail.setVisibility(View.GONE);
//                load_fail_layout.setVisibility(View.GONE);
                jiazai_layout.setVisibility(View.GONE);
            }
        }
    }

    private void loadingTimeout() {
        loadfail.setVisibility(View.GONE);
    }


    /**
     * 检验手机号是否存在
     */
    private void loadCheackAccount() {
        loninActivityPresenter.loadCheackAccount(TextUitl.getString(userAccount));
        isTouch = true;
        loading(false, true);
    }


    /**
     * 获取验证码
     */
    private void loadCode() {
        timeCount.start();
        loninActivityPresenter.loadCode(TextUitl.getString(userAccount));
    }

    /**
     * 获取验证码成功
     * @param bean
     */
    @Override
    public void loadCodeSuccess(GetVerificationCodeBean bean) {
        boolean success = bean.isSuccess();
        if (success){
            ToastUtils.showShort(Login_Activity.this, "验证码已发送");
        } else {
            loadedType(false);
        }
    }

    /**
     * 获取验证码失败
     */
    @Override
    public void loadCodeFailure() {
        loadedType(false);
    }



    /**
     * 校验手机号成功
     * @param bean
     */
    @Override
    public void loadCheackAccountSuccess(VerifyPhotoNumberBean bean) {
        boolean returnValue = bean.isReturnValue();
        if (returnValue){
            loadGetSecretKey();
        } else {
            loading(false, false);
            ToastUtils.showShort(Login_Activity.this, "该账号不存在");
        }
    }

    /**
     * 校验手机号失败
     */
    @Override
    public void loadCheackAccountFailure() {
        loadedType(false);
        loading(false, false);
    }



    /**
     * 获取手机key
     */
    private void loadGetSecretKey() {
        account = userAccount.getText().toString().trim();
        loninActivityPresenter.loadGetSecreKey(account);
    }

    /**
     * 获取手机key成功
     * @param bean
     */
    @Override
    public void loadGetSecreKeySuccess(GetVerificationCodeBean bean) {
        boolean success = bean.isSuccess();
        isTouch = true;
        if (checkPassword()){
            if (success && bean != null){
                String returnValue = bean.getReturnValue();
                if (returnValue.equals(sp.getKey())){
                    loadLogin(true);
                } else {
                    if (usercode_lay.getVisibility() == View.GONE){
                        loading(false, false);
                        ToastUtils.showShort(Login_Activity.this, "请获取验证码");
                        user_line.setVisibility(View.VISIBLE);
                        usercode_lay.setVisibility(View.VISIBLE);
                    } else {
                        if (checkCode()){
                            if (!isSuccessCode){
                                loadCheckCode(true);
                            } else {
                                loadLogin(true);
                            }
                        } else {
                            loading(false, false);
                        }
                    }
                }
            } else {
                if (checkPassword()){
                    loadLogin(true);
                } else {
                    loading(false, false);
                }
            }
        } else {
            loading(false, false);

        }
    }

    /**
     * 获取手机key失败
     */
    @Override
    public void loadGetSecreKeyOnFailure() {
        loadedType(false);
        loadingTimeout();
    }

    /**
     * 获取手机Key失败
     * @param bean
     */
    @Override
    public void loadGetSecreKeyOnFailure(BaseResponseBean bean) {
        //第一次登录没有key，但是要能够登录
        if (!bean.isSuccess()){
            loadLogin(true);
        }
    }


    /**
     * 验证验证码
     */
    private boolean isSuccessCode = false;
    private void loadCheckCode(final boolean isload) {
        loninActivityPresenter.loadCheckCode(TextUitl.getString(userAccount), TextUitl.getString(usertextcode));
        if (isload){
            loading(false, true);
        }
    }

    /**
     * 验证手机验证码成功
     * @param bean
     */
    @Override
    public void loadCheckCodeSuccess(VerifyNoteBean bean) {
        if (bean != null){
            boolean success = bean.isSuccess();
            VerifyNoteBean.ReturnValueBean returnValue = bean.getReturnValue();
            if (success && returnValue != null) {
                String result = returnValue.getResult()+"";
                if (!TextUitl.isEmpty(result) && result.equals("3")) {
                    isSuccessCode = true;
                    isTouch = true ;
                    loadLogin(false);
                } else {
                    loadedType(false);
                }

            } else {
                loadedType(false);
            }
        }
    }

    /**
     * 验证手机验证码失败
     */
    @Override
    public void loadCheackCodeFailure() {
        loadedType(false);
    }

    /**
     * 登录接口
     */
    private void loadLogin(final boolean isload) {





        JSONObject requestJsonObject = new JSONObject();
        try {
            requestJsonObject.put("username", TextUitl.getString(userAccount));
            requestJsonObject.put("password", TextUitl.getString(userPassword));
            requestJsonObject.put("secretKey", sp.getKey());

        } catch (JSONException e) {
            e.printStackTrace();
        }

        AvcHttpUtils.post(AvcConstants.URLHeaderUserinfo + "login", requestJsonObject, new AvcJsonHttpResponseHandler(Login_Activity.this){
            //储存种类的集合
            private ArrayList<String> detailData = new ArrayList<>();
            //储存区域的集合
            private ArrayList<UserRegionBean> areaData = new ArrayList<>();
            private ArrayList<ArrayList<UserRegionBean>> agencyData = new ArrayList<>();
            @Override
            public void onStart() {
                super.onStart();
                if (isload){
                    loading(false, true);
                }
            }

            @Override
            public void onSuccess(JSONObject object) {
                super.onSuccess(object);
                JSONObject jsonObject = object;
                try {
                    if (!TextUitl.isEmpty(jsonObject.toString())) {
                        boolean success = jsonObject.getBoolean("success");
                        if (success && jsonObject.has("returnValue")) {
                            JSONObject returnValueObject = jsonObject.getJSONObject("returnValue");
                            String userRegionCategoryBeen = returnValueObject.getString("userRegionCategoryBeen").trim();
                            String userAuthTree = returnValueObject.getString("userAuthTree").trim();
                            String sessionid = returnValueObject.getString("sessionid").trim();
                            sp.setSessionId(sessionid);
                            //详情是否显示
                            if (!TextUitl.isEmpty(userRegionCategoryBeen)) {
                                JSONArray userRegionCategoryObjectArray = new JSONArray(userRegionCategoryBeen);
                                for (int n = 0, m = userRegionCategoryObjectArray.length(); n < m; n++) {
                                    JSONObject userRegionCategoryObject = userRegionCategoryObjectArray.getJSONObject(n);
                                    String channelType = userRegionCategoryObject.getString("channelType").trim();
                                    sp.setUserLimits(channelType);
                                    String categoryBaseBeen = userRegionCategoryObject.getString("categoryBaseBeen").trim();
                                    if (!TextUitl.isEmpty(categoryBaseBeen)) {
                                        JSONArray userRegionCategoryBeenArray = new JSONArray(categoryBaseBeen);
                                        for (int u = 0, v = userRegionCategoryBeenArray.length(); u < v; u++) {
                                            if(userRegionCategoryBeenArray.getJSONObject(u) == null || "".equals(userRegionCategoryBeenArray.getJSONObject(u))){

                                            }else{
                                                JSONObject userRegionCategoryBeenObject = userRegionCategoryBeenArray.getJSONObject(u);
                                                detailData.add(userRegionCategoryBeenObject.getString("categoryName").trim());
                                            }
                                        }
                                        LocatityCacheData.detailData = detailData;
                                    }

                                }
                            }

                            if (!TextUitl.isEmpty(userAuthTree)) {
                                //root层
                                JSONObject userAuthTreeObject = returnValueObject.getJSONObject("userAuthTree");
                                String nextIdsuserAuthTreeObject = userAuthTreeObject.getString("nextIds").trim();
                                if (!TextUitl.isEmpty(nextIdsuserAuthTreeObject)) {
                                    //线下
                                    JSONArray nextIdsArray = new JSONArray(nextIdsuserAuthTreeObject);
                                    for (int j = 0, k = nextIdsArray.length(); j < k; j++) {
                                        JSONObject nextIdsObject = nextIdsArray.getJSONObject(j);
                                        UserRegionBean userRegionBean = new UserRegionBean();
                                        userRegionBean.setRegionId(nextIdsObject.getString("regionId").trim());
                                        userRegionBean.setLandName(nextIdsObject.getString("landName").trim());
                                        userRegionBean.setLandLevel(nextIdsObject.getString("landLevel").trim());
                                        userRegionBean.setUserCount(nextIdsObject.getString("userCount").trim());
                                        userRegionBean.setUrl(nextIdsObject.getString("url").trim());
                                        userRegionBean.setJudge(nextIdsObject.getBoolean("judge"));
                                        String nextIdsnextIdsArray81 = nextIdsObject.getString("nextIds").trim();
                                        if (!TextUitl.isEmpty(nextIdsnextIdsArray81)) {
                                            //等同81区域层
                                            JSONArray nextIdsArray81 = new JSONArray(nextIdsnextIdsArray81);
                                            for (int l = 0, z = nextIdsArray81.length(); l < z; l++) {
                                                JSONObject nextIdsObject81 = nextIdsArray81.getJSONObject(l);
                                                UserRegionBean userRegionBean81 = new UserRegionBean();
                                                userRegionBean81.setRegionId(nextIdsObject81.getString("regionId").trim());
                                                userRegionBean81.setLandName(nextIdsObject81.getString("landName").trim());
                                                userRegionBean81.setLandLevel(nextIdsObject81.getString("landLevel").trim());
                                                userRegionBean81.setUserCount(nextIdsObject81.getString("userCount").trim());
                                                userRegionBean81.setUrl(nextIdsObject81.getString("url").trim());
                                                userRegionBean81.setJudge(nextIdsObject81.getBoolean("judge"));
                                                String nextIdsnextIdsArrayagency = nextIdsObject81.getString("nextIds").trim();
//                                                userRegionBean81.setNextIds(nextIdsnextIdsArrayagency);
                                                areaData.add(userRegionBean81);
//                                                LocatityCacheData.areaData = areaData;
                                                if (!TextUitl.isEmpty(nextIdsnextIdsArrayagency)) {
                                                    //等同办事处层
                                                    JSONArray nextIdsArrayagency = new JSONArray(nextIdsnextIdsArrayagency);
                                                    ArrayList<UserRegionBean> temp = new ArrayList<>();
                                                    for (int a = 0, b = nextIdsArrayagency.length(); a < b; a++) {
                                                        JSONObject nextIdsObjectagency = nextIdsArrayagency.getJSONObject(a);
                                                        UserRegionBean userRegionBeanagency = new UserRegionBean();
                                                        userRegionBeanagency.setRegionId(nextIdsObjectagency.getString("regionId").trim());
                                                        userRegionBeanagency.setLandName(nextIdsObjectagency.getString("landName").toString().trim());
                                                        userRegionBeanagency.setLandLevel(nextIdsObjectagency.getString("landLevel").trim());
                                                        userRegionBeanagency.setUserCount(nextIdsObjectagency.getString("userCount").trim());
                                                        userRegionBeanagency.setUrl(nextIdsObjectagency.getString("url").trim());
                                                        userRegionBeanagency.setJudge(nextIdsObjectagency.getBoolean("judge"));
                                                        String nextIdsnextIdsArraycity = nextIdsObjectagency.getString("nextIds").trim();
                                                        if (!TextUitl.isEmpty(nextIdsnextIdsArraycity)) {
                                                            //办事处下市层
                                                            JSONArray nextIdsArraycity = new JSONArray(nextIdsnextIdsArraycity);
                                                            ArrayList<UserRegionBeanChild> tempChild = new ArrayList<>();
                                                            for (int c = 0, d = nextIdsArraycity.length(); c < d; c++) {
                                                                JSONObject nextIdsObjectcity = nextIdsArraycity.getJSONObject(c);
                                                                UserRegionBeanChild userRegionBeancity = new UserRegionBeanChild();
                                                                userRegionBeancity.setRegionId(nextIdsObjectcity.getString("regionId").trim());
                                                                userRegionBeancity.setLandName(nextIdsObjectcity.getString("landName").trim());
                                                                userRegionBeancity.setLandLevel(nextIdsObjectcity.getString("landLevel").trim());
                                                                userRegionBeancity.setUserCount(nextIdsObjectcity.getString("userCount").trim());
                                                                userRegionBeancity.setUrl(nextIdsObjectcity.getString("url").trim());
                                                                userRegionBeancity.setJudge(nextIdsObjectcity.getBoolean("judge"));
                                                                tempChild.add(userRegionBeancity);
                                                            }
                                                            userRegionBeanagency.setDeChilds(tempChild);
                                                        }
                                                        temp.add(userRegionBeanagency);
                                                    }
                                                    agencyData.add(temp);
                                                    LocatityCacheData.agencyData = agencyData;
                                                }
                                            }
                                            LocatityCacheData.areaData = areaData;

                                        }
                                    }
                                }
                            }
                            loadedType(true);
                        } else {
                            loadedType(false);
                        }
                    } else {
                        loadedType(false);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinish() {
                super.onFinish();
                loadedType(false);
            }
        });


    }


    private void loadedType(boolean isSuccess) {
        if (isSuccess) {
            sp.setUserAccount(userAccount.getText().toString().trim());
            if (sp.getRememberPassword()) {
                sp.setUserPassword(userPassword.getText().toString().trim());
            } else {
                sp.setUserPassword("");
            }
            isSuccessCode = false;
            isTouch = true;
//// TODO: 2017/8/17 修改为登录后跳转至指定的模式选择页面
//            Intent intent1 = new Intent(Login_Activity.this, Main_Activity.class);
//            startActivity(intent1);
            Intent intent1 = new Intent(Login_Activity.this, ModuleSelectActivity.class);
            startActivity(intent1);
            this.finish();
            //// TODO: 2017/9/18 修改为登录后判断是否添加了竞品，没有添加--去选择添加/已选择，进入主页
//            getCateSyncInfo();
        } else {
            isTouch = true;
            loading(false, false);
        }
    }



//    private void isShowPassword(boolean isClick) {
//        if (sp.getPasswordShow()) {
//            if (isClick) {
//                sp.setPasswordShow(false);
//                passwordEyeImg.setImageResource(R.mipmap.eyeno);
//                userPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
//            } else {
//                passwordEyeImg.setImageResource(R.mipmap.eye);
//                userPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
//            }
//        } else {
//            if (isClick) {
//                sp.setPasswordShow(true);
//                passwordEyeImg.setImageResource(R.mipmap.eye);
//                userPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
//            } else {
//                passwordEyeImg.setImageResource(R.mipmap.eyeno);
//                userPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
//
//            }
//        }
//    }


    private void isRememberPassword(boolean isClick) {
        if (sp.getRememberPassword()) {
            if (isClick) {
                sp.setRememberPassword(false);
                rememberimg.setImageResource(R.mipmap.select_false);
            } else {
                rememberimg.setImageResource(R.mipmap.select_true);

            }
        } else {
            if (isClick) {
                sp.setRememberPassword(true);
                rememberimg.setImageResource(R.mipmap.select_true);
            } else {
                rememberimg.setImageResource(R.mipmap.select_false);
            }
        }
    }

    /**
     * 验证输入账户
     * @return
     */
    private boolean checkAccount() {
        if (TextUitl.isEmpty(TextUitl.getString(userAccount))) {
            ToastUtils.showShortSnackBar(this, this.getResources().getString(R.string.login_inputaccount));
            return false;
        } else {
            if (TextUitl.isPhone(TextUitl.getString(userAccount)) || TextUitl.isEmail(TextUitl.getString(userAccount))) {
                return true;
            } else {
                ToastUtils.showShortSnackBar(this, "请输入正确的手机号或邮箱");
                return false;
            }
        }
    }

    /**
     * 验证输入密码
     *
     * @return
     */
    private boolean checkPassword() {
        if (TextUitl.isEmpty(TextUitl.getString(userPassword))) {
            ToastUtils.showShortSnackBar(this, this.getResources().getString(R.string.login_inputpassword));
            return false;
        }else {
            if (TextUitl.getString(userPassword).length() < 6 || TextUitl.getString(userPassword).length() > 20) {
                ToastUtils.showShortSnackBar(this, "请输入6~20位的密码");
                return false;
            }
        }

        return true;
    }


    /**
     * 验证验证码
     *
     * @return
     */
    private boolean checkCode() {
        if (TextUitl.isEmpty(TextUitl.getString(usertextcode))) {
            ToastUtils.showShortSnackBar(this, this.getResources().getString(R.string.login_inputcode));
            return false;
        }
//        if (TextUitl.getString(usertextcode).length() < 6) {
//            T.showShortSnackBar(this, "验证码最少6位");
//            return false;
//        }
        return true;
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == 1){
            userPassword.setText("");
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        timeCount.cancel();
        this.unregisterReceiver(myReceiver);

    }
}
